# d = {1:[1, 2], 3:[3, 4]}
# d={1:"john", 3:"peter"}
# d={"john":1,"peter":3}
# print(d.keys())
# print(d.values())
# d["peter"] = 10
# print(d['peter'])

#学生成绩统计
# 每门课学生的成绩
# course_scores = [
#     {'Alice': 85, 'Bob': 90, 'Charlie': 78},
#     {'Alice': 92, 'Bob': 88, 'Charlie': 85},
#     {'Alice': 79, 'Bob': 94, 'Charlie': 82}
# ]

# n = len(course_scores)
# Alice_sum = 0
# Bob_sum = 0
# Charlie_sum = 0
# for dic in course_scores:
#     for name, score in dic.items():
#         if name == 'Alice':
#             Alice_sum += dic[name]
#         elif name == 'Bob':
#             Bob_sum += dic[name]
#         elif name == 'Charlie':
#             Charlie_sum += dic[name]
# average_Alice = Alice_sum / 3
# average_Bob = Bob_sum / 3
# average_Charlie = Charlie_sum / 3


# # 每门课学生的成绩
# course_scores = [
#     {'Alice': 85, 'Bob': 90, 'Charlie': 78},
#     {'Alice': 92, 'Bob': 88, 'Charlie': 85},
#     {'Alice': 79, 'Bob': 94, 'Charlie': 82}
# ]   

# #初始化一个字典用于存储每个学生的总成绩和课程数
# student_stats = {}

# #遍历每门课程的成绩
# for course in course_scores:
#     #遍历当前课程中的每个学生和成绩
#     for student, score in course.items():
#         #如果学生不在字典中，初始化其总成绩和课程数
#         if student not in student_stats:
#             student_stats[student] = {'total_grade': 0, 'count': 0}
#         #累加学生的总成绩和课程数
#         student_stats[student]['total_grade'] += score
#         student_stats[student]['count'] += 1
# #计算每个学生的平均成绩并储存在字典中
# average_scores = {}
# for student, state in student_stats.items():
#     average_scores[student] = state['total_grade'] / state['count']

# #获取最大值
# lst_score = list(average_scores.values())
# lst_name = list(average_scores.keys())
# for i in range(len(lst_score) - 1):
#     for j in range(i + 1, len(lst_name)):
#         if lst_score[i] < lst_score[j]:
#             lst_score[i], lst_score[j] = lst_score[j], lst_score[i]
#             lst_name[i], lst_name[j] = lst_name[j], lst_name[i]
# print(f'{lst_name[0]},{lst_score[0]:.2f}')


# # 初始货物量
# inventory = {'苹果': 100, '香蕉': 80, '橙子': 120}
# # 进货/销售记录
# transactions = [
#     {'苹果': -20, '香蕉': 30},
#     {'橙子': -50, '苹果': 10}
# ]

# for fruit_name in inventory.keys():
#     for fruit2 in transactions:
#         for fruit2_name in fruit2.keys():
#             if fruit_name == fruit2_name:
#                 inventory[fruit_name] += fruit2[fruit2_name]
                
# for fruit_name in inventory.keys():
#     if inventory[fruit_name] < 0:
#          print(f"{fruit_name}库存不够,请及时补充!!!")

# print(inventory)

# 初始货物量
# inventory = {'苹果': 100, '香蕉': 80, '橙子': 120}
# # 进货/销售记录
# transactions = [
#     {'苹果': -220, '香蕉': 30},
#     {'橙子': -50, '苹果': 10, '西瓜': 50}
# ]

# #遍历进货和销售记录
# for record in transactions:
#     #遍历交易中的商品和数量
#     for fruit, number in record.items():
#         #如果新增了商品，就先初始化为0
#         if fruit not in inventory:
#             inventory[fruit] = 0
#         #更新库存
#         inventory[fruit] += number
        
# for fruit in inventory:
#     #检查是否有数量为负的
#     if inventory[fruit] < 0:
#         print(f"{fruit}库存不够,请及时补充!!!")
# print(inventory)
"""
1需要先遍历这个好友关系表
2创建一个字典，里面存放出新的好友名字和对应的次数
3.查找到次数等于人数 - 1的好友
"""
# # 好友关系表
# friendships = {
#     'Alice': {'Bob', 'Charlie', 'David'},
#     'Bob': {'Alice', 'Charlie'},
#     'Charlie': {'Alice', 'Bob', 'David'},
#     'David': {'Alice', 'Charlie'}
# }

# friends = {}
# #遍历外层字典的值
# for friend_list in friendships.values():
#     #遍历内存集合
#     for name_friend in friend_list:
#         #不在friends就初始化为一下
#         if name_friend not in friends:
#             friends[name_friend] = 0
#         #friends字典中有这个好友就直接把次数+1
#         friends[name_friend] += 1

# for name in friends.keys():
#     #找出共同好友
#     if friends[name] == len(friendships) - 1:
#         print(name)

# 菜品分类信息
menu_categories = {
    '主菜': {'牛排', '披萨', '寿司'},
    '配菜': {'薯条', '沙拉', '烤蔬菜'},
    '饮品': {'可乐', '咖啡', '果汁'}
}